<?php
namespace Admin\Controller;
use Think\Controller;
class CpController extends Controller{
	function cpflAdd(){
		if(IS_POST){
			$auth_mode = M('cpfl');
			$result=$auth_mode->create();
			if($auth_mode->add($result)){
				$this->success('添加成功');
			}else{
				$this->error('添加失败');
			}
		}else{
			//读取pid为0的一级分类
			$auth_model = M('cpfl');
			$auth_list=$auth_model->where('cl_pid=0')->select();
			$this->assign('auth_list',$auth_list);
			$this->display();	
		}
	}
	function cpAdd(){
		if(IS_POST){

		}else{
			//读取pid为0的一级分类
			$auth_model = M('cpfl');
			$auth_list=$auth_model->where('cl_pid=0')->select();
			$this->assign('auth_list',$auth_list);
			$this->display();	
		}
	}
	    //下拉框查看三级分类
	 function getCate(){
            //1 接受cate_id
            $cate_id = I('get.cl_id');
            //2 实例化cate模型
            $cate_model = D('cpfl');
            //3 查询cate_pid = $cate_id 子类
            $cate_list=$cate_model->where("cl_pid=$cate_id")->select();
            //将cate_list拼接为字符串
            $result='';
            foreach ($cate_list as $value){
                $result .= "<option value='{$value["cl_id"]}'>{$value['cl_name']}</option>";
            }
            //4 将二维数组转为接送返回前台
            echo ($result);
    }
    function get_img(){
    	$file = $_FILES;
    	$list = app_upload_image($file);
	    oss_upload($list);
	    $url = get_url($list);		
	    if($url == false){
	    	$result = array('errno'=>1,'data'=>$url);
	    	echo json_encode($result);
	    }elseif($url == ''){
	    	$result = array('errno'=>1,'data'=>$url);
	    	echo json_encode($result);
	    }else{
	    	$result = array('errno'=>0,'data'=>$url);
	    	echo json_encode($result);
	    }
    }
}